import { Component,Input } from "@angular/core";
import {NzModalService,NzModalSubject,NzNotificationService} from "ng-zorro-antd";
import { Config } from "./../../../../service/config";
import { HttpServcie } from "../../../../service/http.service";
import {SpotCheckPlan} from "../../bean/spotCheckPlan";
import { Router } from "@angular/router";



@Component({
  selector: "spot-object-detailsInterface",
  templateUrl: "spot-object-detailsInterface.html",
  styleUrls: ["spot-object-detailsInterface.scss"]
})
export class SpotObjectDetailsInterface {

  // 定义数据对象用于界面
  public planData:any=[];
  // 定义计划名称下拉数据类型
  public options:any=[];
  // 定义实施对象下拉数据类型
  public objects:any=[];
  // 定义多选框选择事件
  public allChecked: any = false;
  // 定义多选框
  public indeterminate: any = false;
  // 定义下拉计划值
  public planValue:string="";
  // 定义实施对象下拉值
  public objValue:string="";
  // 定义开始时间
  public startDate:any=null;
  // 定义结束时间
  public endDate:any=null;
  // 定义表头名称
  public modelTitle = "新增";
  // 定义模板类型
  public modal: any = 0;
  // 定义模板服务
  public currentModal: NzModalSubject;
  //表格
  config: any = Config;
  // 定义初始化实体类
  public spotCheckPlan:SpotCheckPlan=new SpotCheckPlan();
  // 定义总条数
  public total:any;
  // 定义选中的数据
  public clickItemDate:any=[];
  // 定义点击的行数据
  public clumeData:any;
  functions: any = [];
  @Input()
  inValue: any = [];

  picList = [];

  constructor(

    private httpServcie: HttpServcie,
    private _notification: NzNotificationService,
    private nsub: NzModalSubject,
    private router: Router,
    private modalService: NzModalService
  ) {
    JSON.parse(window.localStorage.getItem("user"));
    this.spotCheckPlan.pageSize = 10;
    this.spotCheckPlan.currentPage = 1;
  }

  ngOnInit() {
    /**
     * 初始化数据表格
     */
    this.queryData();


  }

  //查询
  queryData() {
    this.httpServcie.queryPlanDetails(this.inValue).subscribe(data => {
      if (data.status == "200") {
        console.log(data);
        if (data.data) {
          this.planData = data.data;
          /*if(this.planData !=null && this.planData.length>0){
            for(let i=0;i<this.planData.length;i++){
              let pram = this.planData[i];
              /!*if(pram.picUrl !=null && pram.picUrl !=''){
                this.planData[i].picUrl = this.config.IP+this.config.API.upload+"/"+pram.picUrl;
              }*!/
            }
          }*/
          console.log(this.planData);

          this.total = data.data.length;
        } else {
          this.planData = [];
        }
      } else {
        this._notification.create("error", "错误提示", data.message);
      }
    });
  }
  //全选
  checkAll(value) {
    if (value) {
      this.planData.forEach(data => {
        if (!data.disabled) {
          data.checked = true;
        }
      });
    } else {
      this.planData.forEach(data => (data.checked = false));
    }
  }

  //table加载数据时
  displayDataChange($event) {
    this.planData = $event;
    this.refreshStatus();
  }

  //重置选择框
  refreshStatus() {
    const allChecked = this.planData.every(
      value => value.disabled || value.checked
    );
    const allUnChecked = this.planData.every(
      value => value.disabled || !value.checked
    );
    this.allChecked = allChecked;
    this.indeterminate = !allChecked && !allUnChecked;
  }


  //分页
  nzPageSizeChange(event) {
    this.spotCheckPlan.pageSize = event;
    this.spotCheckPlan.currentPage = 1;
    this.queryData();
  }

  //输入框的方法
  nzPageIndexChange(event) {
    this.spotCheckPlan.currentPage = event;
    this.queryData();
  }

  //当前页
  nzPageIndexClickChange(event) {
    this.spotCheckPlan.currentPage = event;
    this.queryData();
  }

  getPics(pic) {
    if (pic) {
      return pic.split(",");
    } else {
      return [];
    }
  }

  showLargeImage(titlepic, contentpic, footerpic, img) {
    this.picList = [];
    this.picList.push(img);
    this.currentModal = this.modalService.open({
      title: titlepic,
      content: contentpic,
      footer: footerpic,
      maskClosable: false,
      width: 800,
      zIndex: 900,
      style: {
        top: "20px"
      },
      onOk() {
        console.log("Click ok");
      }
    });
  }




}
